<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在线支付 - 医疗预约系统</title>
    <link rel="stylesheet" href="statics/css/hisStyle.css">
    <style>
        /* 统一的样式变量 */
        :root {
            --primary-color: #3498db;
            --primary-hover: #2980b9;
            --secondary-color: #95a5a6;
            --secondary-hover: #7f8c8d;
            --success-color: #27ae60;
            --error-color: #e74c3c;
            --text-primary: #2c3e50;
            --text-secondary: #7f8c8d;
            --bg-light: #f8f9fa;
            --bg-white: #ffffff;
            --border-color: #ddd;
            --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            --border-radius: 8px;
            --container-width: 800px;
        }
        
        /* 全局样式 */
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f7fa;
            margin: 0;
            padding: 0;
        }
        
        /* 头部样式 */
        .header {
            background-color: var(--text-primary);
            color: white;
            padding: 20px 0;
            margin-bottom: 30px;
        }
        
        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        
        /* 面包屑导航 */
        .breadcrumb {
            background-color: #ecf0f1;
            padding: 10px 0;
            margin-bottom: 20px;
        }
        
        .breadcrumb-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        
        .breadcrumb a {
            color: var(--primary-color);
            text-decoration: none;
        }
        
        /* 容器样式 */
        .container {
            max-width: var(--container-width);
            margin: 0 auto;
            padding: 0 20px;
        }
        
        /* 支付容器 */
        .payment-container {
            background: var(--bg-white);
            border-radius: 10px;
            padding: 30px;
            box-shadow: var(--shadow);
        }
        
        /* 标题样式 */
        h2 {
            color: var(--text-primary);
            margin-bottom: 25px;
            text-align: center;
            font-size: 28px;
        }
        
        /* 预约信息 */
        .appointment-info {
            background-color: var(--bg-light);
            padding: 20px;
            border-radius: var(--border-radius);
            margin-bottom: 30px;
        }
        
        .appointment-info h3 {
            color: var(--text-primary);
            margin-bottom: 15px;
            font-size: 18px;
        }
        
        .appointment-details {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
        }
        
        .detail-item {
            color: var(--text-secondary);
            line-height: 1.6;
        }
        
        .detail-item strong {
            color: var(--text-primary);
        }
        
        /* 支付方式 */
        .payment-methods {
            margin-bottom: 30px;
        }
        
        .payment-methods h3 {
            color: var(--text-primary);
            margin-bottom: 15px;
            font-size: 18px;
        }
        
        .payment-options {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 15px;
        }
        
        .payment-option {
            border: 2px solid var(--border-color);
            border-radius: var(--border-radius);
            padding: 15px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
            background-color: var(--bg-white);
        }
        
        .payment-option:hover {
            border-color: var(--primary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        
        .payment-option.selected {
            border-color: var(--primary-color);
            background-color: #f0f8ff;
        }
        
        .payment-option input[type="radio"] {
            display: none;
        }
        
        .payment-option .icon {
            font-size: 24px;
            margin-bottom: 10px;
        }
        
        /* 表单样式 */
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: var(--text-primary);
            font-weight: bold;
        }
        
        .form-control {
            width: 100%;
            padding: 12px;
            border: 1px solid var(--border-color);
            border-radius: 5px;
            font-size: 16px;
            box-sizing: border-box;
            transition: border-color 0.3s ease;
        }
        
        .form-control:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }
        
        /* 按钮样式 */
        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            font-weight: bold;
            transition: all 0.3s ease;
        }
        
        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }
        
        .btn-primary:hover {
            background-color: var(--primary-hover);
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
        }
        
        .btn-secondary {
            background-color: var(--secondary-color);
            color: white;
        }
        
        .btn-secondary:hover {
            background-color: var(--secondary-hover);
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(149, 165, 166, 0.3);
        }
        
        /* 表单操作区域 */
        .form-actions {
            text-align: center;
            margin-top: 30px;
        }
        
        .form-actions .btn {
            margin: 0 10px;
            min-width: 120px;
        }
        
        /* 消息提示 */
        .error-message {
            color: var(--error-color);
            background-color: #fdf2f2;
            border: 1px solid #fecaca;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        
        .success-message {
            color: var(--success-color);
            background-color: #f0f9f0;
            border: 1px solid #c3e6c3;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        
        /* 必填标记 */
        .required {
            color: var(--error-color);
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .appointment-details {
                grid-template-columns: 1fr;
            }
            
            .payment-options {
                grid-template-columns: 1fr 1fr;
            }
            
            .form-actions .btn {
                display: block;
                width: 100%;
                margin: 10px 0;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-content">
            <h1>医疗预约系统</h1>
            <c:choose>
                <c:when test="${not empty sessionScope.loginUser}">
                    <span>欢迎，${sessionScope.loginUser.username}</span>
                </c:when>
                <c:otherwise>
                    <a href="auth/login" class="btn btn-primary">登录</a>
                    <a href="auth/register" class="btn btn-secondary" style="margin-left: 10px;">注册</a>
                </c:otherwise>
            </c:choose>
        </div>
    </div>

    <div class="breadcrumb">
        <div class="breadcrumb-content">
            <a href="frontend/index">首页</a> > 
            <span>在线支付</span>
        </div>
    </div>

    <div class="container">
        <div class="payment-container">
            <h2>在线支付</h2>

            <!-- 错误提示 -->
            <c:if test="${not empty error}">
                <div class="error-message">
                    ${error}
                </div>
            </c:if>

            <!-- 成功提示 -->
            <c:if test="${not empty success}">
                <div class="success-message">
                    ${success}
                </div>
            </c:if>

            <div class="appointment-info">
                <h3>预约信息</h3>
                <div class="appointment-details">
                    <div class="detail-item">
                        <strong>预约号：</strong>${appointment.number}
                    </div>
                    <div class="detail-item">
                        <strong>患者姓名：</strong>${appointment.patientName}
                    </div>
                    <div class="detail-item">
                        <strong>联系电话：</strong>${appointment.patientPhone}
                    </div>
                    <div class="detail-item">
                        <strong>医生：</strong>${appointment.visit.doctorName}
                    </div>
                    <div class="detail-item">
                        <strong>科室：</strong>${appointment.visit.department.deptName}
                    </div>
                    <div class="detail-item">
                        <strong>就诊日期：</strong>${appointment.visit.visitDate}
                    </div>
                </div>
            </div>

            <form action="frontend/payment" method="post">
                <input type="hidden" name="appointmentId" value="${appointment.appointmentId}">
                
                <div class="form-group">
                    <label for="amount">支付金额 <span class="required">*</span></label>
                    <input type="number" id="amount" name="amount" class="form-control" 
                           value="100.00" min="0.01" step="0.01" required>
                </div>

                <div class="payment-methods">
                    <h3>选择支付方式</h3>
                    <div class="payment-options">
                        <label class="payment-option">
                            <input type="radio" name="payMethod" value="微信支付" checked>
                            <div class="icon">💚</div>
                            <div>微信支付</div>
                        </label>
                        <label class="payment-option">
                            <input type="radio" name="payMethod" value="支付宝">
                            <div class="icon">🔵</div>
                            <div>支付宝</div>
                        </label>
                        <label class="payment-option">
                            <input type="radio" name="payMethod" value="银行卡">
                            <div class="icon">💳</div>
                            <div>银行卡</div>
                        </label>
                        <label class="payment-option">
                            <input type="radio" name="payMethod" value="现金">
                            <div class="icon">💰</div>
                            <div>现金</div>
                        </label>
                    </div>
                </div>

                <div class="form-actions">
                    <a href="frontend/my-appointments" class="btn btn-secondary">稍后支付</a>
                    <button type="submit" class="btn btn-primary">立即支付</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        // 支付方式选择效果
        document.querySelectorAll('.payment-option').forEach(option => {
            option.addEventListener('click', function() {
                // 移除所有选中状态
                document.querySelectorAll('.payment-option').forEach(opt => {
                    opt.classList.remove('selected');
                });
                // 添加选中状态
                this.classList.add('selected');
            });
        });

        // 表单验证
        document.querySelector('form').addEventListener('submit', function(e) {
            const amount = document.getElementById('amount').value;
            const payMethod = document.querySelector('input[name="payMethod"]:checked');
            
            if (!amount || parseFloat(amount) <= 0) {
                alert('请输入有效的支付金额');
                e.preventDefault();
                return;
            }
            
            if (!payMethod) {
                alert('请选择支付方式');
                e.preventDefault();
                return;
            }
        });
    </script>
</body>
</html>
